package com.situ.wms.service;

import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionIdListener;
import javax.servlet.http.HttpSessionListener;

/**
 * Application Lifecycle Listener implementation class OnLineNumberListener
 *
 */
@WebListener
public class OnLineNumberListener implements HttpSessionListener  {

  
    public void sessionCreated(HttpSessionEvent se)  { 
        HttpSession session =se.getSession();
        ServletContext application = session.getServletContext();
        Object attribute =application.getAttribute("count");
        if(null==attribute) {
        	application.setAttribute("count", 1);
        }else {
        	int count =(int)attribute;
        	application.setAttribute("count", ++count);
        }
    }


 

    public void sessionDestroyed(HttpSessionEvent se)  { 

    	HttpSession session =se.getSession();
    	ServletContext application =session.getServletContext();
    	int count=(int)application.getAttribute("count");
    	application.setAttribute("count", --count);
    }




	
}
